/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            aCarDetailHisInfo: {
                cars: [],
                carId: '',
                memberId: '',
                carNum: '',
                carNumLike: '',
                logStartTime: '',
                logEndTime: '',
                paId: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('aCarDetailHis', 'switch', function (_data) {
                $that.aCarDetailHisInfo.carId = _data.carId;
                $that.aCarDetailHisInfo.carNum = _data.carNum;
                $that.aCarDetailHisInfo.paId = _data.paId;
                $that.aCarDetailHisInfo.memberId = _data.memberId;
                $that.aCarDetailHisInfo.carNumLike = _data.carNumLike;
                $that.aCarDetailHisInfo.logStartTime = _data.logStartTime;
                $that.aCarDetailHisInfo.logEndTime = _data.logEndTime;
                $that.aCarDetailHisInfo.staffNameLike = _data.staffNameLike;
                $that._loadACarDetailHisData(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('aCarDetailHis', 'notify',
                function (_data) {
                    $that._loadACarDetailHisData(DEFAULT_PAGE, DEFAULT_ROWS);
                });
            vc.on('aCarDetailHis', 'paginationPlus', 'page_event',
                function (_currentPage) {
                    $that._loadACarDetailHisData(_currentPage, DEFAULT_ROWS);
                });
        },
        methods: {
            _loadACarDetailHisData: function (_page, _row) {
                let param = {
                    params: {
                        carNum: $that.aCarDetailHisInfo.carNum,
                        carNumLike: $that.aCarDetailHisInfo.carNumLike,
                        logStartTime: $that.aCarDetailHisInfo.logStartTime,
                        logEndTime: $that.aCarDetailHisInfo.logEndTime,
                        staffNameLike: $that.aCarDetailHisInfo.staffNameLike,
                        page: _page,
                        row: _row
                    }
                };
                //发送get请求
                vc.http.apiGet('/car.queryAdminHisOwnerCar',
                    param,
                    function (json) {
                        let _roomInfo = JSON.parse(json);
                        $that.aCarDetailHisInfo.cars = _roomInfo.data;
                        vc.emit('aCarDetailHis', 'paginationPlus', 'init', {
                            total: _roomInfo.records,
                            dataCount: _roomInfo.total,
                            currentPage: _page
                        });
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _qureyACarDetailHis: function () {
                $that._loadACarDetailHisData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _getHisOperate: function (_car) {
                let _carCount = 0;
                $that.aCarDetailHisInfo.cars.forEach(item => {
                    if (_car.bId == item.bId) {
                        _carCount += 1;
                    }
                });
                if (_carCount <= 1) {
                    if (_car.operate == 'ADD') {
                        return '添加';
                    }
                    if (_car.operate == 'DEL') {
                        return '删除';
                    }
                    return "-"
                }
                if (_car.operate == 'ADD') {
                    return '修改(新)';
                }
                if (_car.operate == 'DEL') {
                    return '修改(旧)';
                }
                return "-"
            }
        }
    });
})(window.vc);